package com.zdb.algorithm.kmp;

public class VoilenceMatch {

    public static void main(String[] args) {

        String str = "aabbcasddasdf;lajsdflkasd;fjas";
        String subStr = "asdf";
        for (int i = 0; i < str.length() - subStr.length(); i++) {
            if(voilenceMatch(str, subStr, i)) {
                System.out.println("成功匹配，位置为：" + i);
                break;
            }else{
                System.out.println("第" +i  + "次匹配失败");
            }
        }
    }

    public static boolean voilenceMatch(String str, String subStr, int sIndex) {
        // str从sIndex开始循环匹配subStr,如果成功，返回true,否则返回false

        int begin = sIndex;
        for (int i = 0; i < subStr.length(); ) {
            if(str.charAt(begin) == subStr.charAt(i)) {
                i++;
                begin++;
            } else {
                return false;
            }
        }

        return true;
    }
}
